package org.wuliu.Controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.wuliu.dao.*;
import org.wuliu.pojo.*;
import org.wuliu.utils.*;

import java.util.List;

@Controller
@RequestMapping("/perm")
@CrossOrigin(value = "*")
public class PermController {
    @Autowired
    private PermDao permDao;
    @Autowired
    private RolePermDao rolePermDao;
    @RequestMapping("/all")
    @ResponseBody
    public ResponseResult getAll(){
        List<Perm> list=permDao.getByPid(1);
        return new ResponseResult(list);
    }
    @RequestMapping("/show/{roleId}")
    @ResponseBody
    public Integer[] getRolePerm(@PathVariable Integer roleId){
        Integer[] ids=permDao.getRolePerm(roleId);
        return ids;
    }
    @RequestMapping("/update")
    @ResponseBody
    public ResponseResult add(String idstr,Integer id){
        String[] ids=idstr.split(",");
        rolePermDao.deleteBy(id);
        rolePermDao.inserts(ids,id);
        return ResponseResult.createSuccessResUle();
    }
    @RequestMapping("/getByJi")
    @ResponseBody
    public ResponseResult getByJi(Integer id){
        List<Perm> list=permDao.getByJi(id);
        return new ResponseResult(list);
    }
    @RequestMapping("/addshow")
    @ResponseBody
    public ResponseResult addshow(Perm perm){
        permDao.add(perm);
        return ResponseResult.createSuccessResUle();
    }
}
